package com.pipayshop.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pipayshop.entity.ShopCommodityLiveInfo;
import com.pipayshop.entity.dto.ShopCommodityLiveInfoListDTO1;
import com.pipayshop.entity.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 酒店的房型表 Mapper 接口
 * </p>
 *
 * @author zxb
 * @since 2023-08-02
 */
@Mapper
public interface HotelShopCommodityLiveInfoMapper extends BaseMapper<ShopCommodityLiveInfo> {

    @Update("UPDATE store_commodity_live_info SET inventory = inventory - #{number}, monthly_sales = monthly_sales + #{number} WHERE room_id = #{roomId}")
    int updateHotelInventoryAndSales(@Param("roomId") String roomId, @Param("number") int number);

    @Update("UPDATE store_commodity_info SET residue = residue - #{number}, monthly_sales = monthly_sales + #{number} WHERE commodity_id = #{commodityId}")
    int updateResidueAndSales(@Param("commodityId") String commodityId, @Param("number") int number);

    @Select("SELECT count(*) from store_commodity_info where commodity_id=#{commodityId}")
    int selectCommodityCount(@Param("commodityId") String commodityId);

    List<ShopCommodityLiveInfoListVO> selectShopCommodityLiveInfoList(@Param("shopId")String shopId);

    List<ShopCommodityLiveInfo> selectRoomCommodityList(@Param("shopId")String shopId);


    ShopCommodityLiveInfoVO selectByRoomId(@Param("roomId")String roomId);


    @Select("select basics from store_commodity_live_info where room_id = #{roomId}")
    String getBasic(@Param("roomId")String roomId);

    @Select("select bath from store_commodity_live_info where room_id = #{roomId}")
    String getBath(@Param("roomId")String roomId);

    @Select("select appliance from store_commodity_live_info where room_id = #{roomId}")
    String getAppliance(@Param("roomId")String roomId);

    List<ShopCommodityLiveVO> selectShopCommodityLiveVO(@Param("limit")Integer limit, @Param("pages")Integer pages);

    Integer selectAllShopCommodityLiveVO();

    int reduceLiveStock(@Param("num")Integer num,@Param("commodityId")String commodityId);

    /**
     * 根据购买数量、商品id =》商品库存复原
     * @return
     */
    int addLiveStock(@Param("num")Integer num,@Param("commodityId")String commodityId);

    /**
     * 查出酒店下面所有的房间，条件：价格（非必要）
     * @param hotelInfo
     * @return
     */
    List<ShopCommodityLiveInfoVO3> selectALlByPrice(ShopCommodityLiveInfoListDTO1 hotelInfo);

    int takeOffRoom(@Param("roomId") String roomId);
}
